import java.io.File;

import java.util.Scanner;

public class fileZip {
    public static void renameFiles(String path, String oldExt, String newExt) {
        File file = new File(path);

        if (!file.exists()) {
            System.err.println("文件路径不存在！");

            return;

        }

        File[] files = file.listFiles();

        if (files.length <= 0) {
            System.err.println("当前路径文件不存在！");

            return;

        }

        for (File f : files) {
            if (f.isDirectory()) {
                renameFiles(f.getPath(), oldExt, newExt);

            } else {
                String name = f.getName();

                if (name.endsWith("." + oldExt)) {
                    name = name.substring(0, name.lastIndexOf(".") + 1);

                    name += newExt;

                    f.renameTo(new File(f.getParent() + "\\" + name));

                }

            }

        }

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入要修改文件后缀名的文件夹:");

        String path = sc.nextLine();

        System.out.println("请输入修改前的后缀名:");

        String oldExt = sc.nextLine();

        System.out.println("请输入修改后的后缀名:");

        String newExt = sc.nextLine();

        renameFiles(path, oldExt, newExt);

        System.out.println("操作完成");

    }

}